const app = getApp()

Page({
    data: {
        config: app.globalData.config,
        tabs: [{
            index: 0,
            text: "维修"
        }, {
            index: 1,
            text: "保养"
        }],
        modalName: '',
        TabCur: 0,
        categoryIndex: null,
        childIndex: null,
        categoryName: 'fatherModal',

        arr: [{
                id: 1,
                text: "电视",
                list: [{
                    id: 10,
                    text: 'sumsang',

                }, {
                    id: 11,
                    text: "honor"
                }]
            },
            {
                id: 2,
                text: "手机",
                list: [{
                    id: 20,
                    text: 'iphone',
                }, {
                    id: 21,
                    text: "xiaomi"
                }]
            },
            {
                id: 3,
                text: "电器",
                list: [{
                    id: 10,
                    text: 'sumsang',

                }, {
                    id: 11,
                    text: "huawei"
                }]
            },
        ],
        region: [],
        buydate: null,
        servicedate: null,
        names: null,
        ids: null,
        reason: null,
        phone: null,
        address: null,
        person: null,
        product: [],
    },
    onLoad() {},
    onShow() {

    },

    tabSelect(e) {
        let value = e.currentTarget.dataset.index;
        this.setData({
            TabCur: value
        })
    },
    showModal(e) {
        this.setData({
            modalName: e.currentTarget.dataset.target
        })
    },
    showModal1(e) {
        this.setData({
            modalName: 'bottomModal'
        })
    },
    showModal2(e) {
        this.setData({
            categoryName: 'fatherModal'
        })
    },
    hideModal(e) {
        this.setData({
            modalName: null,
            names: [],
            ids: [],
            categoryIndex: null,
            childIndex: null,
        })
    },
    selectCategory(e) {
        let index = e.currentTarget.dataset.index;
        let arr = this.data.arr;
        let names = [];
        let ids = [];
        names.push(arr[index].text);
        ids.push(arr[index].id);
        let categoryName = this.data.categoryName;
        if (arr[index].list.length > 0) {
            categoryName = "childModal";
        }
        this.setData({
            categoryIndex: index,
            categoryName: categoryName,
            names: names,
            ids: ids,
        })
    },
    selectChild(e) {
        let childIndex = e.currentTarget.dataset.index;
        let arr = this.data.arr;
        let categoryIndex = this.data.categoryIndex;
        let obj = arr[categoryIndex].list[childIndex];
        let names = [...this.data.names];
        let ids = [...this.data.ids];
        if(ids.length==2){
            names[1] =obj.text;
            ids[1] = obj.id;
        }else{
            names.push(obj.text);
            ids.push(obj.id);
        }
       
        this.setData({
            childIndex: childIndex,
            names: names,
            ids: ids,
        })
    },
    serviceChange(e) {
        this.setData({
            servicedate: e.detail.value,
        })
    },
    buyChange(e) {
        this.setData({
            buydate: e.detail.value,
        })
    },
    reason(e) {
        this.setData({
            reason: e.detail.value,
        })
    },
    person(e) {
        this.setData({
            person: e.detail.value,
        })
    },
    phone(e) {
        this.setData({
            phone: e.detail.value,
        })
    },
    address(e) {
        this.setData({
            address: e.detail.value,
        })
    },
    bindRegionChange(e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            region: e.detail.value
        })
    },
    submit() {

    },
})